<template>
  <div class="splash-container">
    <img src="../../assets/image.png" alt="启动页背景" class="splash-bg" />
    <div class="content-container">
      <van-button type="default" size="small" class="skip-btn" @click="skip">
        跳过 {{ countdown }}
      </van-button>
      <div class="logo-container">
        <van-icon name="shopping-bag-o" size="48" class="logo-icon" />
        <p class="logo-text">DAISY SHOP</p>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref, onMounted } from 'vue'
import { useRouter } from 'vue-router'

const router = useRouter()
const countdown = ref(5)
let timer = null

// 倒计时处理
const startCountdown = () => {
  timer = setInterval(() => {
    if (countdown.value > 0) {
      countdown.value--
    } else {
      clearInterval(timer)
      router.push('/home') // 替换成实际跳转路由
    }
  }, 1000)
}

// 跳过倒计时
const skip = () => {
  clearInterval(timer)
  router.push('/home') // 替换成实际跳转路由
}

onMounted(() => {
  startCountdown()
})

onUnmounted(() => {
  clearInterval(timer)
})
</script>

<style scoped>
.splash-container {
  position: relative;
  height: 100vh;
  overflow: hidden;
}
.splash-bg {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.content-container {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 20px;
  box-sizing: border-box;
}
.skip-btn {
  position: absolute;
  top: 20px;
  right: 20px;
  background: rgba(0, 0, 0, 0.6);
  color: white;
  border-radius: 20px;
  padding: 5px 15px;
}
.logo-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  margin-bottom: 50px;
}
.logo-icon {
  color: white;
  background: white;
  border-radius: 50%;
  padding: 15px;
  background: rgba(255, 255, 255, 0.8);
}
.logo-text {
  color: white;
  margin-top: 10px;
  font-size: 16px;
}
</style>
